﻿SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
GO
CREATE TABLE dbo.bht_PayU_PaymentTransaction
	(
	TransactionId int NOT NULL IDENTITY (1, 1),
	PosId int NOT NULL,
	PosAuthKey nchar(7) NOT NULL,
	PaymentType nvarchar(10) NOT NULL,
	ChargeValue numeric(12, 2) NOT NULL,
	Description nvarchar(50) NOT NULL,
	FirstName nvarchar(100) NOT NULL,
	LastName nvarchar(100) NOT NULL,
	EMail nvarchar(100) NOT NULL,
	ClientIP nvarchar(15) NOT NULL,
	Status int NOT NULL,
	OrderID int NULL,
	Description2 nvarchar(1024) NULL,
	DescriptionBank nvarchar(27) NULL,
	Street nvarchar(10) NULL,
	StreetNumber nvarchar(10) NULL,
	FlatNumber nvarchar(10) NULL,
	City nvarchar(100) NULL,
	PostCode nvarchar(20) NULL,
	Country nvarchar(100) NULL,
	Phone nvarchar(100) NULL,
	Language char(10) NULL,
	JavaScript bit NULL,
	PaybackLogin nvarchar(40) NULL,
	Sig nvarchar(32) NULL,
	Ts nvarchar(1000) NULL
	)  ON [PRIMARY]
GO
ALTER TABLE dbo.bht_PayU_PaymentTransaction ADD CONSTRAINT
	PK_bht_PayU_PaymentTransaction PRIMARY KEY CLUSTERED 
	(
	TransactionId
	) ON [PRIMARY]

GO
ALTER TABLE dbo.bht_PayU_PaymentTransaction ADD CONSTRAINT
	FK_bht_PayU_PaymentTransaction_bht_PayU_PaymentType FOREIGN KEY
	(
	PaymentType
	) REFERENCES dbo.bht_PayU_PaymentType
	(
	PaymentKey
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
ALTER TABLE dbo.bht_PayU_PaymentTransaction ADD CONSTRAINT
	FK_bht_PayU_PaymentTransaction_bht_PayU_PaymentStatus FOREIGN KEY
	(
	Status
	) REFERENCES dbo.bht_PayU_PaymentStatus
	(
	StatusId
	) ON UPDATE  NO ACTION 
	 ON DELETE  NO ACTION 
	
GO
GO
CREATE PROCEDURE [dbo].[bhp_PayU_PaymentTransactionSaveNew] (
	@PosId int,
	@PosAuthKey nchar(7),
	@PaymentType nvarchar(10),
	@ChargeValue numeric(12, 2),
	@Description nvarchar(50),
	@FirstName nvarchar(100),
	@LastName nvarchar(100),
	@EMail nvarchar(100),
	@ClientIP nvarchar(15),
	@Status int,
	@OrderID int,
	@Description2 nvarchar(1024),
	@DescriptionBank nvarchar(27),
	@Street nvarchar(10),
	@StreetNumber nvarchar(10),
	@FlatNumber nvarchar(10),
	@City nvarchar(100),
	@PostCode nvarchar(20),
	@Country nvarchar(100),
	@Phone nvarchar(100),
	@Language char(10),
	@JavaScript bit,
	@PaybackLogin nvarchar(40),
	@Sig nvarchar(32),
	@Ts nvarchar(1000)
)
AS
BEGIN
	INSERT INTO bht_PayU_PaymentTransaction (
		[PosId],
		[PosAuthKey],
		[PaymentType],
		[ChargeValue],
		[Description],
		[FirstName],
		[LastName],
		[EMail],
		[ClientIP],
		[Status],
		[OrderID],
		[Description2],
		[DescriptionBank],
		[Street],
		[StreetNumber],
		[FlatNumber],
		[City],
		[PostCode],
		[Country],
		[Phone],
		[Language],
		[JavaScript],
		[PaybackLogin],
		[Sig],
		[Ts]
	) VALUES (
		@PosId,
		@PosAuthKey,
		@PaymentType,
		@ChargeValue,
		@Description,
		@FirstName,
		@LastName,
		@EMail,
		@ClientIP,
		@Status,
		@OrderID,
		@Description2,
		@DescriptionBank,
		@Street,
		@StreetNumber,
		@FlatNumber,
		@City,
		@PostCode,
		@Country,
		@Phone,
		@Language,
		@JavaScript,
		@PaybackLogin,
		@Sig,
		@Ts 
	)
	
	SELECT @@IDENTITY as TransactionId
END
